package com.resourcestore.action;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.List;

import com.resourcestore.utils.CommonUtil;
import com.resourcestore.action.BaseAction;
import com.resourcestore.dao.MajorDao;
import com.resourcestore.dao.MajorFileSrcDao;
import com.resourcestore.model.Major;
import com.resourcestore.model.MajorFileSrc;
import com.resourcestore.utils.tag.Pagination;

public class ExpertMajorAction extends BaseAction {
	

	private MajorDao majorDao = new MajorDao();
	private List<Major> listMajor;
	private Pagination pagination = new Pagination();
	private Major major;
	
	private MajorFileSrc majorFileSrc;
	private List<MajorFileSrc> listMajorFileSrc;
	private MajorFileSrcDao majorFileSrcDao = new MajorFileSrcDao();
	
	

	/**
	 * 专业查询
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listMajorReadExpert() {
		
			major = new Major();
			pagination.setTotal(majorDao.queryMajorNum(major));
			listMajor = majorDao.selectMajorPage(major,pagination);

			for (int i = 0; i < listMajor.size(); i++) {
				try {
					listMajor.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajor.get(i).getGmtCreated()));
					listMajor.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajor.get(i).getGmtModified()));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
		return newpath("/ExpertMajor/listMajorRead.jsp");
		
	}
	
	/**
	 * 专业搜索 带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListMajorReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			major.setMajorgroupName(new String(major.getMajorgroupName().getBytes("iso-8859-1"),"UTF-8"));
			major.setMajorName(new String(major.getMajorName().getBytes("iso-8859-1"),"UTF-8"));
			major.setAuthor(new String(major.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		pagination.setTotal(majorDao.queryMajorNum(major));
		listMajor = majorDao.selectMajorPage(major,pagination);
		
		//将bigint数字处理为时间格式
		for (int i = 0; i < listMajor.size(); i++) {
			try {
				listMajor.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajor.get(i).getGmtCreated()));
				listMajor.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajor.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertMajor/listMajorRead.jsp");
	}

	
	/**
	 * 专业文件资源查询
	 * @throws ParseException 
	 * 
	 */
	
	public String listMajorFileSrcReadExpert(){
		majorFileSrc = new MajorFileSrc();
		//MajorFileCategoryId如果为空设置为-2
		majorFileSrc.setMajorFileCategoryId(-2);
		pagination.setTotal(majorFileSrcDao.queryMajorFileSrcNum(majorFileSrc));
		listMajorFileSrc = majorFileSrcDao.selectMajorFileSrcPage(majorFileSrc,pagination);
		
		for (int i = 0; i < listMajorFileSrc.size(); i++) {
			
			//将文件类型代码转换为名称
			listMajorFileSrc.get(i).setMajorFileTypeName(this.showFileCate(listMajorFileSrc.get(i).getMajorFileType()));
			//将bigint数字处理为时间格式
			try {
					listMajorFileSrc.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajorFileSrc.get(i).getGmtCreated()));
					listMajorFileSrc.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajorFileSrc.get(i).getGmtModified()));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
		}
		
		return newpath("/ExpertMajor/listMajorFileSrcRead.jsp");
	}
	
	
	/**
	 * 专业文件资源搜索 带分页
	 * @throws ParseException 
	 * 
	 */
	public String searchListMajorFileSrcReadExpert(){
		
		//对内容进行urldecoder解码
		try {
			majorFileSrc.setMajorFileName(new String(majorFileSrc.getMajorFileName().getBytes("iso-8859-1"),"UTF-8"));
			majorFileSrc.setMajorFileRemark(new String(majorFileSrc.getMajorFileRemark().getBytes("iso-8859-1"),"UTF-8"));
			//majorFileSrc.setMajorGroupName(new String(majorFileSrc.getMajorGroupName().getBytes("iso-8859-1"),"UTF-8"));
			majorFileSrc.setMajorName(new String(majorFileSrc.getMajorName().getBytes("iso-8859-1"),"UTF-8"));
			majorFileSrc.setAuthor(new String(majorFileSrc.getAuthor().getBytes("iso-8859-1"),"UTF-8"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		//MajorFileCategoryId如果为空设置为-2
		if(majorFileSrc.getMajorFileCategoryId()==0){
			majorFileSrc.setMajorFileCategoryId(-2);
		}
		
		pagination.setTotal(majorFileSrcDao.queryMajorFileSrcNum(majorFileSrc));
		listMajorFileSrc = majorFileSrcDao.selectMajorFileSrcPage(majorFileSrc,pagination);
		
		
		for (int i = 0; i < listMajorFileSrc.size(); i++) {
			//将文件类型代码转换为名称
			listMajorFileSrc.get(i).setMajorFileTypeName(this.showFileCate(listMajorFileSrc.get(i).getMajorFileType()));
			//将bigint数字处理为时间格式
			try {
			listMajorFileSrc.get(i).setGmtCreatedString(CommonUtil.getSysTimeFormatString(listMajorFileSrc.get(i).getGmtCreated()));
			listMajorFileSrc.get(i).setGmtModifiedString(CommonUtil.getSysTimeFormatString(listMajorFileSrc.get(i).getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return newpath("/ExpertMajor/listMajorFileSrcRead.jsp");
	}
	
	public List<Major> getListMajor() {
		return listMajor;
	}

	public void setListMajor(List<Major> listMajor) {
		this.listMajor = listMajor;
	}

	public Pagination getPagination() {
		return pagination;
	}

	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

	public Major getMajor() {
		return major;
	}

	public void setMajor(Major major) {
		this.major = major;
	}

	public MajorFileSrc getMajorFileSrc() {
		return majorFileSrc;
	}

	public void setMajorFileSrc(MajorFileSrc majorFileSrc) {
		this.majorFileSrc = majorFileSrc;
	}

	public List<MajorFileSrc> getListMajorFileSrc() {
		return listMajorFileSrc;
	}

	public void setListMajorFileSrc(List<MajorFileSrc> listMajorFileSrc) {
		this.listMajorFileSrc = listMajorFileSrc;
	}


}
